/* $Header: px_cmds.c,v 2.2 01/10/02 10:29:22 przybyls Exp $ */

/***********************************************************************/
/*                                                                     */
/*                  Copyright Hewlett-Packard Co. 1991                 */
/*                                                                     */
/***********************************************************************/

/***********************************************************************/
/* MODULE NAME: PX_cmds.c                                              */
/* ============                                                        */
/*                                                                     */
/* Author:  Bob Cook                                                   */
/*                                                                     */
/* MODULE PURPOSE: This module will handle the pass through commands   */
/*          from the sampler serial port to the host computer.         */
/*                                                                     */
/*                                                                     */
/***********************************************************************/

/*
 */

/*****************************/
/*   GLOBAL INCLUDE FILES    */
/*****************************/

#include <typedefs.h>
#include <stddef.h>
#include <error.h>
#include <i_op.h>
#include <config.h>
#include <mio.h>
#include <cmd_set.h>
#include <cmdproc.h>
#include <method.h>
#include <hostutil.h>
#include <duart.h>

/*****************************/
/*   LOCAL INCLUDE FILES     */
/*****************************/



/*****************************/
/*   GLOBAL VARIABLES        */
/*****************************/


/*****************************/
/*   EXTERNAL VARIABLES      */
/*****************************/

extern CMD_QUEUE_TYPE  PX_Cmd_Q;

/*****************************/
/*   LOCAL DEFINES           */
/*****************************/

/*****************************/
/*   STATIC VARIABLES        */
/*****************************/

/*****************************/
/*   MACROS                  */
/*****************************/



/*****************************/
/*   IMPLEMENT SECTION       */
/*****************************/





/***********************************************************************/
/* FUNCTION: PX_Cmds                                                  */
/* ========                                                            */
/*                                                                     */
/* PURPOSE: if a command is available it calls function which passes   */
/*             command from sampler serial port to the host computer.  */
/*                                                                     */
/* RETURNED VALUE: none                                                */
/*                                                                     */
/* WARNINGS:                                                           */
/*                                                                     */
/***********************************************************************/

void PX_Cmds(void)
{
U_INT16       len,i;
BIT8         *p_out_buf;
MIO_HDR_TYPE *p_out_hdr;
CMD_TYPE     *p_in_hdr;
BIT8         *p_in_buf;
U_INT16       port;
U_INT16       path;

   INTERRUPTS_OFF;
   if(PX_Cmd_Q.num_entries != 0)
   {
      path = (U_INT16)(NextCmd_Dsap(PX_Cmd_Q,1) - 'A');
      port = Com_Path[path].host_port;

      switch(port)
      {
      case INJECTOR1_PORT:
      case HOST_PORT:
         p_out_hdr = AcquirePutBuf(&p_out_buf);
         if(p_out_hdr)
         {
            GetCmd(p_in_hdr,PX_Cmd_Q);
            p_in_buf = p_in_hdr->parms;
            INTERRUPTS_ON;

            len = StrLen(p_in_buf);

            /* over write dsap with correct dsap */
            Copy2(&Com_Path[path].hdsap.char_hdsap[0],p_out_buf);
            p_in_buf += 2;
            p_out_buf += 2;

            for( i = 2; i < len; i++ )
            {
               *p_out_buf++ = *p_in_buf++;
            }

            /*
             *  port assignments:  see hostcmd.h
             *   DRTA_PORT       0
             *   DRTB_PORT       1
             *   IB_PORT         2
             *   MIO_PORT        3
             */

            PutMsg(p_out_hdr,port,len);

            /* return input message buffer */
            ReturnGetBuf(p_in_hdr);
         }   /* if */
         else
         {
            INTERRUPTS_ON;
         }
         return;
      default:
         /* error port not set up correctly */
         INTERRUPTS_ON;
         return;
      } /* switch */
   } /* if */
   else
   {
      INTERRUPTS_ON;
   }
   return;
}

/***********************************************************************/
/* END FUNCTION: PX_Cmds                                               */
/***********************************************************************/

